<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Package" ToolsVersion="4.0">

	<!-- 
  	****************************************
  	* IMPORTS
	****************************************
  -->
	<PropertyGroup>
		<MSBuildUmbracoTasksPath>$(MSBuildProjectDirectory)\Tools\MSBuildUmbracoTasks</MSBuildUmbracoTasksPath>
	</PropertyGroup>

	<Import Project="$(MSBuildUmbracoTasksPath)\MSBuild.Umbraco.Tasks.Targets" />

	<!-- 
  	****************************************
  	* PROPERTIES
	****************************************
  -->
	<PropertyGroup>
		<PackageVersion>0.0.6</PackageVersion>
	</PropertyGroup>

	<PropertyGroup>
		<RootDir>$(MSBuildProjectDirectory)</RootDir>
		<BuildDir>$(RootDir)\Build</BuildDir>
		<PackageDir>$(BuildDir)</PackageDir>
		<ProjectDir>$(RootDir)\Contour.Contrib</ProjectDir>
	</PropertyGroup>

	<!-- 
  	****************************************
  	* TARGETS
	****************************************
  -->

	<!-- CLEAN -->
	<Target Name="Clean">
		<RemoveDir Directories="$(BuildDir)" Condition="Exists('$(BuildDir)')" />
		<RemoveDir Directories="$(PackageDir)" Condition="Exists('$(PackageDir)')" />
		<MakeDir Directories="$(BuildDir)" />
		<MakeDir Directories="$(PackageDir)" />
	</Target>

	<!-- COMPILE -->
	<Target Name="Compile" DependsOnTargets="Clean">
		<MSBuild Projects="$(ProjectDir)\Contour.Contrib.csproj" />
	</Target>

	<!-- PREPAIRE FILES -->
	<Target Name="PrepairFiles" DependsOnTargets="Compile">
		<ItemGroup>
			<BinFiles Include="$(ProjectDir)\Bin\AreYouAHuman.dll" />
			<BinFiles Include="$(ProjectDir)\Bin\Contour.Contrib.dll" />
			<BinFiles Include="$(ProjectDir)\Bin\Recaptcha.dll" />
			<ImageFiles Include="$(ProjectDir)\Resources\umbraco\plugins\umbracoContour\images\*.*" />
			<PackageFile Include="$(RootDir)\Package.xml" />
		</ItemGroup>
		<Copy SourceFiles="@(BinFiles)" DestinationFolder="$(BuildDir)\bin" />
		<Copy SourceFiles="@(ImageFiles)" DestinationFolder="$(BuildDir)\umbraco\plugins\umbracoContour\images" />
		<Copy SourceFiles="@(PackageFile)" DestinationFolder="$(BuildDir)" />
	</Target>

	<!-- MANIFEST -->
	<Target Name="Manifest" DependsOnTargets="PrepairFiles">
		<ItemGroup>
			<ManifestFiles Include="$(BuildDir)\**\*" Exclude="$(BuildDir)\Package.xml" />
		</ItemGroup>
		<ManifestUpdate ManifestFile="$(BuildDir)\Package.xml"
			WorkingDirectory="$(BuildDir)"
			PackageVersion="$(PackageVersion)"
			Files="@(ManifestFiles)" />
	</Target>

	<!-- PACKAGE -->
	<Target Name="Package" DependsOnTargets="Manifest">
		<ItemGroup>
			<PackageFiles Include="$(BuildDir)\**\*.*" />
		</ItemGroup>
		<Package ManifestFile="$(BuildDir)\Package.xml"
		   WorkingDirectory="$(BuildDir)"
		   OutputDirectory="$(PackageDir)"
		   Files="@(PackageFiles)" />
	</Target>

</Project>